// TOWN SCRIPT
//    Town 12: Llylgamyn Mine

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

// flags:

begintownscript;

variables;

short i, x, y, choice;

body;

beginstate INIT_STATE;
	turn_off_training(1);
	set_crime_tolerance(3);

	set_name(9, "Overseer Joe");
	set_char_dialogue_pic(9, 1922, 0);

	// if Trebor has been killed, all in mine hate party
	if ((get_flag(50, 2) > 0) && (get_flag(12, 13) == 0)) {
		set_flag(12, 13, 1);
		message_dialog("It appears as if the mine workers don't care much for you.", "");
		make_town_hostile();
	}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
	if (get_ran(1, 0, 100) < 5)
		text_bubble_on_char(10, "Hi Ho, Hi Ho");
	if (get_ran(1, 0, 100) < 5)
		text_bubble_on_char(14, "It's off to work we go");
	if (get_ran(1, 0, 100) < 5)
		text_bubble_on_char(18, "With a pick and shovel");
	if (get_ran(1, 0, 100) < 5)
		text_bubble_on_char(22, "It's off to work we go");
break;

beginstate 10;
	message_dialog("The bookshelf if full of mine ledgers.", "From the looks of it, the mine has seen better days.");
break;

beginstate 11;
	if (get_flag(x, y) == 0) {
		reset_dialog();
		add_dialog_str(0, "You see a glint of gold in the ground here.", 0);
		if (has_item(318)) {
			add_dialog_choice(0, "Leave it");
			add_dialog_choice(1, "Dig it up");
		}
		else {
			add_dialog_choice(0, "OK");
		}
		choice = run_dialog(0);
		if (choice == 2) {
			reset_dialog();
			add_dialog_str(0, "You dig down in the dirt with your shovel and recover some gold ore.", 0);
			add_dialog_str(1, "Boy, do you feel rich.", 0);
			add_dialog_choice(0, "OK");
			choice = run_dialog(0);
			set_flag(x, y, 1);
			i = get_ran(1, 1, 3);
			while (i > 0) {
				reward_give(388);
				i = i - 1;
			}
		}
	}
break;

beginstate 12;
	x = 12;
	y = 0;
	set_state_continue(11);
break;

beginstate 13;
	x = 12;
	y = 1;
	set_state_continue(11);
break;

beginstate 14;
	x = 12;
	y = 2;
	set_state_continue(11);
break;

beginstate 15;
	x = 12;
	y = 3;
	set_state_continue(11);
break;

beginstate 16;
	x = 12;
	y = 4;
	set_state_continue(11);
break;

beginstate 17;
	x = 12;
	y = 5;
	set_state_continue(11);
break;

beginstate 18;
	x = 12;
	y = 6;
	set_state_continue(11);
break;

beginstate 19;
	x = 12;
	y = 7;
	set_state_continue(11);
break;

beginstate 20;
	x = 12;
	y = 8;
	set_state_continue(11);
break;

beginstate 21;
	x = 12;
	y = 9;
	set_state_continue(11);
break;

beginstate 22;
	x = 12;
	y = 10;
	set_state_continue(11);
break;

beginstate 23;
	x = 12;
	y = 11;
	set_state_continue(11);
break;

beginstate 24;
	x = 12;
	y = 12;
	set_state_continue(11);
break;
